package top.huahaizhi.zhihu.daily;

import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.WindowManager;

import butterknife.ButterKnife;
import butterknife.Unbinder;

public abstract class BaseActivity extends AppCompatActivity {

    protected static final int NO_LAYOUT = -1;

    protected static final String TAG = "BaseActivity";

    private Unbinder unbinder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT&&isStatusBar()) {
            WindowManager.LayoutParams localLayoutParams = getWindow().getAttributes();
            localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags);
        }
        int layoutId = getLayoutId(savedInstanceState);
        Log.d(TAG, "onCreate: create layout(" + layoutId + ")");
        if (layoutId != -1) setContentView(layoutId);
        Log.d(TAG, "onCreate: setContentView");
        unbinder = ButterKnife.bind(this);
        Log.d(TAG, "onCreate: ButterKnife bind view on " + this.getClass().getSimpleName());
        initData();
        Log.d(TAG, "onCreate: init Data finish");
        setParams();
        Log.d(TAG, "onCreate: set params finish");
        accessNet();
        Log.d(TAG, "onCreate: access netWork finish");
    }

    protected boolean isStatusBar(){
        return true;
    }

    public abstract int getLayoutId(Bundle savedInstanceState);

    protected void setParams() {
    }

    protected void initData() {
    }

    protected void accessNet() {
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbinder.unbind();
    }
}
